<%--
  Created by IntelliJ IDEA.
  User: 22531
  Date: 2021/6/9
  Time: 16:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
    <script type="text/javascript" src="/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.edatagrid.js"></script>
    <script src="/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function (){
            $('#SelectCourse').edatagrid({
                url:'/stu/getAllCourseBySelect',
                columns:[[
                    {field:'id',title:'ID',width:100,align:'center'},
                    {field:'name',title:'课程名称',width:100,align:'center'},
                    {field:'place',title:'上课地点',width:100,align:'center'},
                    {field:'c_year',title:'年度',width:100,align:'center'},
                    {field:'tea_name',title:'上课老师',width:100,align:'center'},
                    {field:'c_type',title:'课程类型',width:100,align:'center'},
                ]],
                rownumbers:true,
                pagination: true,
                pageSize:10,
                pageList:[10,20,30,40,50],
                singleSelect: true,
                toolbar:[{
                    iconCls: 'icon-reload',
                    text:'刷新',
                    handler: function(){
                        $('#SelectCourse').edatagrid('reload');
                    }
                },'-',{
                    iconCls: 'icon-add',
                    text: '加入选课',
                    handler: addCourse,
                }],
            });
        })
    </script>
    <script type="text/javascript">
        function addCourse() {
            var row = $('#SelectCourse').edatagrid('getSelected');
            $.messager.confirm('是否加入', '确定?', function(r){
                if (r){
                    $.get("/stu/joinSelectCourse",{
                        "id":row.id,
                         "stu_id":'${sessionScope.stu.id}',
                    },function (data){
                        if(true==data.msg){
                            $('#SelectCourse').edatagrid('cancelEdit', editIndex)
                                .edatagrid('deleteRow', editIndex);
                        }else {
                            alert("加入失败"+data.error);
                        }
                        editIndex = undefined;
                        $('#SelectCourse').edatagrid('reload');
                    })
                }
            });
        }
    </script>
</head>
<body>
<div class="easyui-panel" data-options="fit:true,border:false">
    <table id="SelectCourse"></table>
</div>
</body>
</html>
